package challengesManager;

import java.awt.BorderLayout;
import java.util.Timer;

import javax.swing.JPanel;

import control.Control;
import control.SimpleTimer;

import challengeGUI.ChallengeGUI;
import challengeGUI.FallingBoxGUI;
import data.ChallengeData;
import data.Player;

public class FallingBoxManager extends ChallengeManagerAdapter<FallingBoxGUI>{
	private long elementInBoxFallenTimeStamp = -1;


	public FallingBoxManager(Control c, ChallengeData d ){
		super(c,d);
	}

	@Override
	public void initGui(JPanel placeHolderPanel){
		this.gui = new FallingBoxGUI(this);
		super.initGui(placeHolderPanel);
	}


	@Override
	public void playerBuzz(Player pl) {
		int revealInfo;
		c.playerHasPressed(pl);
		if(elementInBoxFallenTimeStamp == -1){
			gui.freeze();
			revealInfo = -1;
			pl.setPoints(pl.getPoints() - 1);

		}else{
			gui.freeze();
			revealInfo = (int)(SimpleTimer.getTimeStamp() - elementInBoxFallenTimeStamp);
			pl.setPoints(pl.getPoints() + 1);
			++pointsDistributed;
		}

		gui.reveal(revealInfo);
	}

	@Override
	public void perfectBuzzMoment(boolean state) {
		if(state)this.elementInBoxFallenTimeStamp = SimpleTimer.getTimeStamp();
	}

	@Override
	public void animationOver() {
		elementInBoxFallenTimeStamp = -1;
		super.animationOver();
	}

}
